// ServidorPrincipal.h

#ifndef __NAMESERVER_H
#define __NAMESERVER_H

#include <fstream>
#include <iostream>
#include <map>
#include <sstream>

#include <stdio.h>
#include <stdlib.h>
#include "TcpListener.h"
#include "Thread.h"

using namespace std;

namespace PracticaCaso
{
	class ServidorPrincipal: public TcpListener {
		private:
			string domain;
			string pais;
			map<string, string> dns2IpPortMap;
		public:
			string fichero;
			ServidorPrincipal(int p, string m);
			ServidorPrincipal(const ServidorPrincipal&);
			ServidorPrincipal & operator = (const ServidorPrincipal &);
			~ServidorPrincipal();
			string calcular(string dnsName);
			void loadMappings(string mappinsFileName);
			friend ostream & operator << (ostream &os, ServidorPrincipal &n);

	};


	class ServidorPrincipalThread: public Thread {
		private:
			TcpClient* dnsClient;
			ServidorPrincipal& dnsServer;
			void run();
		public:
			ServidorPrincipalThread(TcpClient* c, ServidorPrincipal& s): dnsClient(c), dnsServer(s) {}
			~ServidorPrincipalThread();
	};
};
#endif
